<template>
	<view>
		<view class="flex1">
			<view class="" >
				<view class="" style="display: flex;align-items: center;" v-if="isshow">
					剩余取餐时间：
					<uni-countdown :show-day="false" :day="1" :hour="hours" :minute="minutes"
						:second="seconds"></uni-countdown>
				</view>
				<view class="" v-else>
					未到取餐时间！取餐时间为{{timeBegin}} - {{timeEnd}}
				</view>
			</view>
			<image @click="opents" src="/static/icon/ts.png" mode=""></image>
		</view>
		<!-- <clearts ref="popupts"></clearts> -->
	</view>
</template>

<script>
	export default {
		name: "countdown",
		props: {
			timeBegin: {
				default: '00:00:00'
			},
			timeEnd: {
				default: '00:00:00'
			}
		},
		data() {
			return {
				hours: 0,
				minutes: 0,
				seconds: 0,
				isshow: false
			};
		},
		created() {
			console.log(this.timeBegin);
			var timeString = this.timeEnd // 时分秒字符串
			var currentDate = new Date(); // 当前日期对象
			var dateString = currentDate.toDateString(); // 获取当前日期的字符串表示（不包含时分秒）
			var timeBeginString = dateString + ' ' + this.timeBegin; // 拼接日期和时分秒字符串
			var timeEndString = dateString + ' ' + timeString; // 拼接日期和时分秒字符串
			
			var timestampBegin = Date.parse(timeBeginString); // 将日期时间字符串转换为时间戳
			var timestampEnd = Date.parse(timeEndString); // 将日期时间字符串转换为时间戳
			var nowtimestamp = Date.parse(new Date());
			if (nowtimestamp - timestampBegin > 0) {
				this.isshow = true
			} else {
				this.isshow = false
			}
			let now = timestampEnd - nowtimestamp
			this.hours = Math.floor(now / 3600000);
			this.minutes = Math.floor((now % 3600000) / 60000);
			this.seconds = Math.floor((now % 60000) / 1000);
		},
		methods: {
			opents() {
				// this.$refs.popupts.open()
				this.$emit('opents')
			},
		}
	}
</script>

<style lang="scss">
	.flex1 {
		display: flex;
		align-items: center;
		height: 68rpx;
		background: #F3F3F3;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 26rpx;
		color: #000000;
		justify-content: space-between;
		padding: 0rpx 20rpx;
		box-sizing: border-box;
		width: 710rpx;
		margin: 0 auto;

		image {
			width: 32rpx;
			height: 33rpx;
		}
	}
</style>